package com.zynn.count.handler;

import com.zynn.count.base.BaseEntity;
import com.zynn.count.exception.BaseException;
import com.zynn.count.result.Result;
import com.zynn.count.result.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 *
 * @author yu_chen
 * @date 2018/4/22 13:52
 */
@ControllerAdvice
public class BaseExceptionHandler {


    /**
     * 统一异常处理
     *
     * @param baseException 基础的异常
     * @return 失败的result
     */
    @ExceptionHandler(value = BaseException.class)
    @ResponseBody
    public Result handlerBaseException(BaseException baseException) {

        return ResultUtil.fail(baseException.getCode(), baseException.toString());
    }
}
